
<?php
	session_start();
	header("content-type:text/html;charset=utf-8");
	//连接数据库
    $link = mysqli_connect("localhost","root","20201002983","test");
	if (!$link) {
		die("连接失败: " . mysqli_connect_error());
	}
	//接收$_POST用户名和密码
	$username = $_POST['name'];
	$password = $_POST['password'];
	//查看表user用户名与密码和传输值是否相等
	$sql = "SELECT * FROM users WHERE name = '$username' AND password = '$password'";
	//result必需规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。
	$result = mysqli_query($link,$sql);
	$num = mysqli_num_rows($result);//函数返回结果集中行的数量
	//判断是否登录后显示或跳转
	if($num){
		$url = '../index.html';
        echo "<script>alert('成功进入四次元世界');</script>";
		echo "<script>location.href='$url'</script>";
	}else{
		$url = '../login.html';
		echo '<script>alert("世界连接失败！这个白菜不存在或者进入口令（密码）不对");</script>';
		echo "<script>location.href='$url'</script>";
	}
	mysqli_close($link);//关闭数据库
 ?>
